Initial Setup
Alright, so there's two things we need to do before anything else.
First, we need some terminal software. This is the application that runs the command-line environment.
Just about every operating system will come with a built-in terminal, like macOS' Terminal.app, or Windows' Command Prompt. These applications work, but they're pretty underwhelming. Most developers opt to use something else.
The choice of terminal application isn't super important, as long as you're using something modern. That said, I have two main recommendations:
- Hyper. Hyper is a modern, multi-platform terminal application. It's beautiful, and comes with some handy modern features, like the ability to split into multiple panes.
- If you use VS Code as your code editor, VS Code comes with a powerful, modern terminal built in. This is nice, since it means your code and terminal can run side-by-side in the same application. You can pop open the terminal in VS Code by selecting View → Terminal.
There are many other valid options. For a long time, I used iTerm2 on macOS. I've also heard good things about the modern Windows Terminal. If you already have a terminal application you're happy with, there's no need to change!
Now, the terminal application is only half of the equation. We also need to make sure we're running the right shell language.
When we type a command into the terminal and press “enter”, that command will be interpreted by the shell language. It's essentially the environment running within the terminal application.
The most popular shell language is Bash. When you see command-line instructions online, it's likely that the instructions are assuming Bash. This is the default shell language used by most Linux distributions.
Modern macOS versions ship with Zsh instead of Bash, but Zsh is very similar: it's part of the same "family", and shares almost all of the same commands. For our purposes, they can be used interchangeably.
If you're using either Linux or macOS, you're good to go. Your computer is already using an "industry standard" shell language. If you're using Windows, however, we have a bit of work to do.
Windows setup
Alright, first, let me preface this by emphatically admitting that I am not an expert when it comes to Windows development. Please take everything I'm about to say with a grain of salt. 😅
Bash is a Linux-based shell language, and it won't run natively in Windows. Fortunately, newer versions of Windows come with the ability to install and run Linux as if it were any other application. This is known as Windows Subsystem for Linux, commonly abbreviated to WSL.
Here's a tutorial that runs through the steps required: How to install and use Zsh in Windows 10.
I ran through these steps myself, and while it's definitely a bit tedious, it does the job!
Once it's set up, you'll be able to configure your terminal application to use Bash or Zsh. Here are some instructions for configuring Hyper to use Zsh.
Our first command
When you first open the terminal application, you're met with this rather unhelpful interface:
Your terminal will likely look a bit different, based on your operating system / terminal application / shell language. Ultimately, however, you'll probably be looking at a single line of text, and a bunch of empty space.
The single line of text is known as a prompt. It's called a “prompt” because it's waiting for you to provide some sort of instruction.
For our first command, enter the text echo "hello world"
and press enter:
The syntax is a bit different, but you can think of commands like built-in JavaScript functions. The echo
command is very similar to the console.log
function in JavaScript.
Like functions, commands take arguments. In this case, echo
takes a single argument, the string to output.
When we press “enter”, the command is immediately executed, and our value is logged. A fresh prompt is rendered below, to let us know that it's ready to receive the next instruction.
And just like that, you've run your first terminal command!